package com.ruoyi.standingbook.lamp.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.standingbook.lamp.domain.vo.LampImportDetailVo;
import com.ruoyi.standingbook.lamp.service.impl.LampExcelService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.lamp.domain.vo.LampImportBaseVo;
import com.ruoyi.standingbook.lamp.domain.bo.LampImportBaseBo;
import com.ruoyi.standingbook.lamp.service.ILampImportBaseService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 路灯管养导入
 *
 * @author cc
 * @date 2023-08-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/lampImportBase")
public class LampImportBaseController extends BaseController {

    private final ILampImportBaseService iLampImportBaseService;
    private final LampExcelService lampExcelService;
    /**
     * 查询路灯管养导入列表
     */
    @SaCheckPermission("standingbook:lampImportBase:list")
    @GetMapping("/list")
    public TableDataInfo<LampImportBaseVo> list(LampImportBaseBo bo, PageQuery pageQuery) {
        return iLampImportBaseService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出路灯管养导入列表
     */
    @SaCheckPermission("standingbook:lampImportBase:export")
    @Log(title = "路灯管养导入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LampImportBaseBo bo, HttpServletResponse response) {
        List<LampImportBaseVo> list = iLampImportBaseService.queryList(bo);
        ExcelUtil.exportExcel(list, "路灯管养导入", LampImportBaseVo.class, response);
    }

    /**
     * 获取路灯管养导入详细信息
     *
     * @param batchNo 主键
     */
    @SaCheckPermission("standingbook:lampImportBase:query")
    @GetMapping("/{batchNo}")
    public R<LampImportBaseVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String batchNo) {
        return R.ok(iLampImportBaseService.queryById(batchNo));
    }

    /**
     * 新增路灯管养导入
     */
    @SaCheckPermission("standingbook:lampImportBase:add")
    @Log(title = "路灯管养导入", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LampImportBaseBo bo) {
        return toAjax(iLampImportBaseService.insertByBo(bo));
    }

    /**
     * 修改路灯管养导入
     */
    @SaCheckPermission("standingbook:lampImportBase:edit")
    @Log(title = "路灯管养导入", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LampImportBaseBo bo) {
        return toAjax(iLampImportBaseService.updateByBo(bo));
    }

    /**
     * 删除路灯管养导入
     *
     * @param batchNos 主键串
     */
    @SaCheckPermission("standingbook:lampImportBase:remove")
    @Log(title = "路灯管养导入", businessType = BusinessType.DELETE)
    @DeleteMapping("/{batchNos}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] batchNos) {
        return toAjax(iLampImportBaseService.deleteWithValidByIds(Arrays.asList(batchNos), true));
    }

    /**
     * 新增导入主
     */
    @SaCheckPermission("standingbook:lampImportBase:add")
    @Log(title = "路灯管养导入", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping("/importData")
    public R<Void> importData(@Validated(AddGroup.class) @RequestBody LampImportBaseBo bo) {
        return toAjax(this.lampExcelService.importExcel(bo));
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "路灯管养数据", LampImportDetailVo.class, response);
    }
}
